package com.dq.usercenter.controller;

import com.dq.commonutils.dto.OrderUserVo;
import com.dq.commonutils.vo.Result;
import com.dq.usercenter.service.UcenterInfoMemberService;
import com.dq.usercenter.vo.UserMemberVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @project: guli_parent
 * @ClassName: UcenterInfoMemberController
 * @author: dq
 * @creat: 2022/8/7 18:14
 */
@RestController
@RequestMapping("educenter/member")
// @CrossOrigin
public class UcenterInfoMemberController {

    @Autowired
    private UcenterInfoMemberService userInfoService;

    /**
     * 根据token获取用户信息
     *
     * @param token
     * @return
     */
    @GetMapping("getUserInfo")
    public Result getUserInfo(@RequestHeader("Authorization") String token) {
        UserMemberVo userMemberVo = userInfoService.getUserInfo(token);
        return Result.success(userMemberVo);
    }


    //用于远程调用单独封装的方法

    /**
     * 根据用户id获取基本信息
     *
     * @param userId
     * @return
     */
    @PostMapping("getOrderUserInfo/{userId}")
    public OrderUserVo getOrderUserInfo(@PathVariable("userId") String userId) {
        OrderUserVo orderUserVo = userInfoService.getOrderUserInfo(userId);
        return orderUserVo;
    }


    /**
     * 获取某一天的总注册人数
     * @param day
     * @return
     */
    @PostMapping("countRegister/{day}")
    public Result findTotalRegisterCountFromOneDay(@PathVariable("day") String day) {
        Integer count = userInfoService.findTotalRegisterCountFromOneDay(day);
        Map<String, Integer> resultMap = new HashMap<>();
        resultMap.put("count", count);
        return Result.success(resultMap);
    }

}
